﻿using System;
using System.Xml.Linq;
using System.Xml.Serialization;
using PortalWeb.Aviation.Core.Entity;
using PortalWeb.Common;

namespace PortalWeb.Flight.Core.Entity
{
    [Serializable]
    public sealed class PassengerBase : IXmlObject
    {
        /// <summary>
        /// 旅客姓名
        /// </summary>
        [XmlElement("name")]
        public string Name { get; set; }

        /// <summary>
        /// 票号
        /// </summary>
        [XmlElement("ticketno")]
        public string TicketNo { get; set; }

        /// <summary>
        /// 航信系统证件类型 	NI  身份证号 	FOID 护照号 	ID  其它类型
        /// </summary>
        [XmlElement("cardtype")]
        public EnumCardType CardType { get; set; }

        /// <summary>
        /// 证件号 
        /// </summary>
        [XmlElement("cardno")]
        public string CardNo { get; set; }

        /// <summary>
        /// 旅客类型 ADT 成人	CHD 儿童	INF  婴儿	UM 无陪伴儿童
        /// </summary>
        [XmlElement("mantype")]
        public EnumPassengerType PassengerType { get; set; }

        public XElement ExportXml()
        {
            XElement xml = new XElement("passenger");
            xml.SetElementValue("name", Name);
            xml.SetElementValue("ticketno", TicketNo);
            xml.SetElementValue("cardtype", CardType);
            xml.SetElementValue("cardno", CardNo);
            xml.SetElementValue("mantype", PassengerType);

            return xml;
        }

        public void ImportXml(XElement xml)
        {
            Name = xml.GetElementValue("name", Name);
            TicketNo = xml.GetElementValue("ticketno", TicketNo);
            CardType = xml.GetElementValue("cardtype", CardType);
            CardNo = xml.GetElementValue("cardno", CardNo);
            PassengerType = xml.GetElementValue("mantype", PassengerType);
        }

        public void ImportXml(string xml)
        {
            try
            {
                ImportXml(XElement.Parse(xml));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + " xml：" + xml, ex);
            }
        }
    }
}
